package com.cyf.db.mapper;

import com.cyf.db.bean.FeeGroup;
import com.cyf.merchat.network.bean.FeegroupListRsp;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FeeGroupMapper {

	@Select("select * from local_feegroup where id = #{id}")
    FeeGroup getById(@Param("id") Integer id);

	// 获取车位预约计费规则
    @Select("select * from local_feegroup where parkingId = #{parkingId} and billingType = 6")
    FeeGroup getBookingFeeGroup(@Param("parkingId") Integer parkingId);

    @Select("select * from local_feegroup where localFeegroupId = #{localFeegroupId} and parkingId = #{parkingId}")
    FeeGroup getByLocalFeegroupIdAndParkingId(@Param("localFeegroupId") Integer localFeegroupId, @Param("parkingId") Integer parkingId);

    @Select("SELECT id, localFeegroupId,name, billingType,fee FROM local_feegroup WHERE " +
            "(billingType=1 or embedType=1 or billingType=7) and `status`=1 and wechatShow = 1 " +
            "and parkingId = #{parkingId}")
    List<FeeGroup> listWechatShowFeeRateByParkingId(@Param("parkingId") Integer parkingId);

   /* // 获取优惠券计费规则
    @Select("select *,localFeegroupId as feeGroupId from local_feegroup where parkingId = #{parkingId} " +
            "and billingType = 5")
    List<FeegroupListRsp> selectByBillingType(@Param("parkingId") Integer parkingId);1
*/
    // 获取优惠券计费规则
    @Select("SELECT fe.*,fe.localFeegroupId as feeGroupId  FROM local_merchant_info AS me LEFT JOIN local_feegroup AS fe ON me.feeGroupId = fe.id OR me.feeGroupId = fe.localFeegroupId and fe.parkingId = #{parkingId} " +
            "WHERE me.id = #{merchatId} AND me.parkingId = #{parkingId} ")
    List<FeegroupListRsp> selectByBillingType(@Param("merchatId") Integer merchatId,@Param("parkingId") Integer parkingId);


    //update local_feegroup
    @Update("update payorder set fee = #{fee} where orderNo = #{orderNo}")
    void updateLocalFeeGroupFee(@Param("orderNo") String orderNo,@Param("fee") Integer fee);

    // 获取单个优惠规则
    @Select("select *,localFeegroupId as feeGroupId from local_feegroup where parkingId = #{parkingId} " +
            "and billingType = 5 and id = #{feeGroupId}")
    FeegroupListRsp parkingByFeegroupId(@Param("parkingId") Integer parkingId,
                                              @Param("feeGroupId") Integer feeGroupId);
}
